//
//  ShopsDetailCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/8/8.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SDWebImage
import SDCycleScrollView


class ShopsDetailCell: BaseTableViewCell {
    
    @IBOutlet weak var bgViewH: NSLayoutConstraint!
    
    var shopName: String?
    
    lazy var names : [String] = {
    
    let temp = [String]()
    
        
    return temp
    
    }()
    
    
    lazy var cycleScrollView : SDCycleScrollView = {
        
        var temp : SDCycleScrollView = SDCycleScrollView(frame:CGRect(x: 0, y: 0, width: KScreenW, height: KScreenW / 750 * 354) , delegate: nil, placeholderImage: UIImage(named: "placeholder"))
        
        temp.autoScrollTimeInterval = 3
        
        temp.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated
        
        temp.pageControlAliment = SDCycleScrollViewPageContolAlimentRight
        
        return temp
        
    }()
    
    
    
    var imgs : [String]?{
    
        didSet{
        
            if imgs == nil {
                 bgViewH.constant = KScreenW / 750 * 354
                cycleScrollView.frame = CGRect(x: 0, y: 0, width: KScreenW, height: KScreenW / 750 * 354)
                return
            }
            
            if imgs!.count > 0 {
                
            }else{
                
             bgViewH.constant = KScreenW / 750 * 354
            cycleScrollView.frame = CGRect(x: 0, y: 0, width: KScreenW, height: KScreenW / 750 * 354)
  
                return
            }
            
            
            if let imageCach = SDWebImageManager.shared().imageCache {
                
                if let tempImage = imageCach.imageFromDiskCache(forKey: imgs![0])  {
                    
                    bgViewH.constant = tempImage.size.height / tempImage.size.width * KScreenW
                    
                    cycleScrollView.frame = CGRect(x: 0, y: 0, width: KScreenW, height: tempImage.size.height / tempImage.size.width * KScreenW)

                }else{
                    
                    bgViewH.constant = KScreenW / 750 * 354
                    
                    cycleScrollView.frame = CGRect(x: 0, y: 0, width: KScreenW, height: KScreenW / 750 * 354)

                }
                
                
                
            }else{
                
                
                bgViewH.constant = KScreenW / 750 * 354
                cycleScrollView.frame = CGRect(x: 0, y: 0, width: KScreenW, height: KScreenW / 750 * 354)

                
                
                
            }
            
            names.removeAll()

            cycleScrollView.imageURLStringsGroup = imgs
            
            if shopName != nil {
                
                for _ in imgs! {
                    
                    names.append(shopName!)
                    
                }
                
                
                cycleScrollView.titlesGroup =  names

                
            }
            
        
        }
    
    
    
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        
        contentView.addSubview(cycleScrollView)

        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
